package com.guo.worktool.service.impl;

import com.guo.worktool.common.model.RequestWorkToolBody;
import com.guo.worktool.manager.factory.StrConvertFactory.ConvertFactory;
import com.guo.worktool.manager.factory.StrConvertFactory.StrConvertService;
import com.guo.worktool.service.NewSQLWorkToolService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class NewSQLWorkToolServiceImpl implements NewSQLWorkToolService {

    private final static String STR_CONVERT = "newSQLWorkToolServiceImpl-strConvert-query";

    @Resource
    private ConvertFactory convertFactory;

    @Override
    @Cacheable(value = STR_CONVERT, key = "#workToolBody.str")
    public String strConvert(RequestWorkToolBody workToolBody) {
        StrConvertService strConvertService = convertFactory.findConvert(workToolBody);
        return strConvertService.convert(workToolBody.getStr());
    }

    @CacheEvict(value = STR_CONVERT, allEntries = true)
    public void delStrConvertCache() {
        log.info("delStrConvertCache all ~~~");
    }
}
